<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>datetimeparse_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_i18n_datetimeparse_test.js.html">datetimeparse_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.i18n.DateTimeParseTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.i18n.DateTimeParseTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.date.Date&#39;);
<a name="line19"></a>goog.require(&#39;goog.i18n.DateTimeFormat&#39;);
<a name="line20"></a>goog.require(&#39;goog.i18n.DateTimeParse&#39;);
<a name="line21"></a>goog.require(&#39;goog.i18n.DateTimeSymbols&#39;);
<a name="line22"></a>goog.require(&#39;goog.i18n.DateTimeSymbols_en&#39;);
<a name="line23"></a>goog.require(&#39;goog.i18n.DateTimeSymbols_fa&#39;);
<a name="line24"></a>goog.require(&#39;goog.i18n.DateTimeSymbols_fr&#39;);
<a name="line25"></a>goog.require(&#39;goog.i18n.DateTimeSymbols_pl&#39;);
<a name="line26"></a>goog.require(&#39;goog.i18n.DateTimeSymbols_zh&#39;);
<a name="line27"></a>goog.require(&#39;goog.testing.ExpectedFailures&#39;);
<a name="line28"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line29"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line30"></a>
<a name="line31"></a>goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_en;
<a name="line32"></a>
<a name="line33"></a>var expectedFailures;
<a name="line34"></a>
<a name="line35"></a>function setUpPage() {
<a name="line36"></a>  expectedFailures = new goog.testing.ExpectedFailures();
<a name="line37"></a>}
<a name="line38"></a>
<a name="line39"></a>function tearDown() {
<a name="line40"></a>  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_en;
<a name="line41"></a>  expectedFailures.handleTearDown();
<a name="line42"></a>}
<a name="line43"></a>
<a name="line44"></a>// Helper equivalent of assertEquals for dates, with day of month optional
<a name="line45"></a>function assertDateEquals(expectYear, expectMonth, expectDate, date) {
<a name="line46"></a>  assertEquals(expectYear, date.getFullYear());
<a name="line47"></a>  assertEquals(expectMonth, date.getMonth());
<a name="line48"></a>  if (expectDate)
<a name="line49"></a>    assertEquals(expectDate, date.getDate());
<a name="line50"></a>}
<a name="line51"></a>
<a name="line52"></a>// Helper equivalent of assertEquals for times, with seconds and milliseconds
<a name="line53"></a>function assertTimeEquals(expectHour, expectMin, expectSec, expectMilli, date) {
<a name="line54"></a>  assertEquals(expectHour, date.getHours());
<a name="line55"></a>  assertEquals(expectMin, date.getMinutes());
<a name="line56"></a>  if (expectSec)
<a name="line57"></a>    assertEquals(expectSec, date.getSeconds());
<a name="line58"></a>  if (expectMilli)
<a name="line59"></a>    assertEquals(expectMilli, date.getTime() % 1000);
<a name="line60"></a>}
<a name="line61"></a>
<a name="line62"></a>// Helper function, doing parse and assert on dates
<a name="line63"></a>function assertParsedDateEquals(expectYear, expectMonth, expectDate,
<a name="line64"></a>    parser, stringToParse, date) {
<a name="line65"></a>  assertTrue(parser.parse(stringToParse, date) &gt; 0);
<a name="line66"></a>  assertDateEquals(expectYear, expectMonth, expectDate, date);
<a name="line67"></a>}
<a name="line68"></a>
<a name="line69"></a>// Helper function, doing parse and assert on times
<a name="line70"></a>function assertParsedTimeEquals(expectHour, expectMin, expectSec, expectMilli,
<a name="line71"></a>    parser, stringToParse, date) {
<a name="line72"></a>  assertTrue(parser.parse(stringToParse, date) &gt; 0);
<a name="line73"></a>  assertTimeEquals(expectHour, expectMin, expectSec, expectMilli, date);
<a name="line74"></a>}
<a name="line75"></a>
<a name="line76"></a>function testNegativeYear() {
<a name="line77"></a>  var date = new Date();
<a name="line78"></a>
<a name="line79"></a>  var parser = new goog.i18n.DateTimeParse(&#39;MM/dd, yyyy&#39;);
<a name="line80"></a>  assertParsedDateEquals(1999, 11 - 1, 22, parser, &#39;11/22, 1999&#39;, date);
<a name="line81"></a>  assertParsedDateEquals(-1999, 11 - 1, 22, parser, &#39;11/22, -1999&#39;, date);
<a name="line82"></a>}
<a name="line83"></a>
<a name="line84"></a>function testEra() {
<a name="line85"></a>  // Bug 2350397
<a name="line86"></a>  if (goog.userAgent.WEBKIT) {
<a name="line87"></a>    // Bug 2350397 Test seems to be very flaky on Chrome. Disabling it
<a name="line88"></a>    return;
<a name="line89"></a>  }
<a name="line90"></a>
<a name="line91"></a>  var date = new Date();
<a name="line92"></a>  var parser = new goog.i18n.DateTimeParse(&#39;MM/dd, yyyyG&#39;);
<a name="line93"></a>  assertParsedDateEquals(-1998, 11 - 1, 22, parser, &#39;11/22, 1999BC&#39;, date);
<a name="line94"></a>  assertParsedDateEquals(0, 11 - 1, 22, parser, &#39;11/22, 1BC&#39;, date);
<a name="line95"></a>  assertParsedDateEquals(1999, 11 - 1, 22, parser, &#39;11/22, 1999AD&#39;, date);
<a name="line96"></a>}
<a name="line97"></a>
<a name="line98"></a>function testFractionalSeconds() {
<a name="line99"></a>  var date = new Date();
<a name="line100"></a>  var parser = new goog.i18n.DateTimeParse(&#39;hh:mm:ss.SSS&#39;);
<a name="line101"></a>
<a name="line102"></a>  assertParsedTimeEquals(11, 12, 13, 956, parser, &#39;11:12:13.956&#39;, date);
<a name="line103"></a>  assertParsedTimeEquals(11, 12, 13, 950, parser, &#39;11:12:13.95&#39;, date);
<a name="line104"></a>  assertParsedTimeEquals(11, 12, 13, 900, parser, &#39;11:12:13.9&#39;, date);
<a name="line105"></a>}
<a name="line106"></a>
<a name="line107"></a>function testAmbiguousYear() {
<a name="line108"></a>  // assume this year is 2006, year 27 to 99 will be interpret as 1927 to 1999
<a name="line109"></a>  // year 00 to 25 will be 2000 to 2025. Year 26 can be either 1926 or 2026
<a name="line110"></a>  // depend on the time being parsed and the time when this program runs.
<a name="line111"></a>  // For example, if the program is run at 2006/03/03 12:12:12, the following
<a name="line112"></a>  // code should work.
<a name="line113"></a>  // assertTrue(parser.parse(&#39;01/01/26 00:00:00:001&#39;, date) &gt; 0);
<a name="line114"></a>  // assertTrue(date.getFullYear() == 2026 - 1900);
<a name="line115"></a>  // assertTrue(parser.parse(&#39;12/30/26 23:59:59:999&#39;, date) &gt; 0);
<a name="line116"></a>  // assertTrue(date.getFullYear() == 1926 - 1900);
<a name="line117"></a>
<a name="line118"></a>  // Since this test can run in any time, some logic needed here.
<a name="line119"></a>
<a name="line120"></a>  var futureDate = new Date();
<a name="line121"></a>  futureDate.setFullYear(futureDate.getFullYear() +
<a name="line122"></a>      100 - goog.i18n.DateTimeParse.ambiguousYearCenturyStart);
<a name="line123"></a>  var ambiguousYear = futureDate.getFullYear() % 100;
<a name="line124"></a>
<a name="line125"></a>  var parser = new goog.i18n.DateTimeParse(&#39;MM/dd/yy HH:mm:ss:SSS&#39;);
<a name="line126"></a>  var date = new Date();
<a name="line127"></a>
<a name="line128"></a>  var str = &#39;01/01/&#39; + ambiguousYear + &#39; 00:00:00:001&#39;;
<a name="line129"></a>  assertTrue(parser.parse(str, date) &gt; 0);
<a name="line130"></a>  assertEquals(futureDate.getFullYear(), date.getFullYear());
<a name="line131"></a>
<a name="line132"></a>  str = &#39;12/31/&#39; + ambiguousYear + &#39; 23:59:59:999&#39;;
<a name="line133"></a>  assertTrue(parser.parse(str, date) &gt; 0);
<a name="line134"></a>  assertEquals(futureDate.getFullYear(), date.getFullYear() + 100);
<a name="line135"></a>
<a name="line136"></a>  // Test the ability to move the disambiguation century
<a name="line137"></a>  goog.i18n.DateTimeParse.ambiguousYearCenturyStart = 60;
<a name="line138"></a>
<a name="line139"></a>  futureDate = new Date();
<a name="line140"></a>  futureDate.setFullYear(futureDate.getFullYear() +
<a name="line141"></a>      100 - goog.i18n.DateTimeParse.ambiguousYearCenturyStart);
<a name="line142"></a>  ambiguousYear = futureDate.getFullYear() % 100;
<a name="line143"></a>
<a name="line144"></a>  var str = &#39;01/01/&#39; + ambiguousYear + &#39; 00:00:00:001&#39;;
<a name="line145"></a>  assertTrue(parser.parse(str, date) &gt; 0);
<a name="line146"></a>  assertEquals(futureDate.getFullYear(), date.getFullYear());
<a name="line147"></a>
<a name="line148"></a>
<a name="line149"></a>  str = &#39;12/31/&#39; + ambiguousYear + &#39; 23:59:59:999&#39;;
<a name="line150"></a>  assertTrue(parser.parse(str, date) &gt; 0);
<a name="line151"></a>  assertEquals(futureDate.getFullYear(), date.getFullYear() + 100);
<a name="line152"></a>
<a name="line153"></a>  // Reset parameter for other test cases
<a name="line154"></a>  goog.i18n.DateTimeParse.ambiguousYearCenturyStart = 80;
<a name="line155"></a>}
<a name="line156"></a>
<a name="line157"></a>function testLeapYear() {
<a name="line158"></a>  var date = new Date();
<a name="line159"></a>
<a name="line160"></a>  var parser = new goog.i18n.DateTimeParse(&#39;MMdd, yyyy&#39;);
<a name="line161"></a>
<a name="line162"></a>  assertParsedDateEquals(2001, 3 - 1, 1, parser, &#39;0229, 2001&#39;, date);
<a name="line163"></a>  assertParsedDateEquals(2000, 2 - 1, 29, parser, &#39;0229, 2000&#39;, date);
<a name="line164"></a>}
<a name="line165"></a>
<a name="line166"></a>function testAbutField() {
<a name="line167"></a>  var date = new Date();
<a name="line168"></a>
<a name="line169"></a>  var parser = new goog.i18n.DateTimeParse(&#39;hhmm&#39;);
<a name="line170"></a>  assertParsedTimeEquals(11, 22, undefined, undefined, parser, &#39;1122&#39;, date);
<a name="line171"></a>  assertParsedTimeEquals(1, 22, undefined, undefined, parser, &#39;122&#39;, date);
<a name="line172"></a>
<a name="line173"></a>  var parser2 = new goog.i18n.DateTimeParse(&#39;hhmmss&#39;);
<a name="line174"></a>  assertParsedTimeEquals(11, 22, 33, undefined, parser2, &#39;112233&#39;, date);
<a name="line175"></a>  assertParsedTimeEquals(1, 22, 33, undefined, parser2, &#39;12233&#39;, date);
<a name="line176"></a>
<a name="line177"></a>  var parser3 = new goog.i18n.DateTimeParse(&#39;yyyyMMdd&#39;);
<a name="line178"></a>  assertParsedDateEquals(1999, 12 - 1, 2, parser3, &#39;19991202&#39;, date);
<a name="line179"></a>  assertParsedDateEquals(999, 12 - 1, 2, parser3, &#39;9991202&#39;, date);
<a name="line180"></a>  assertParsedDateEquals(99, 12 - 1, 2, parser3, &#39;991202&#39;, date);
<a name="line181"></a>  assertParsedDateEquals(9, 12 - 1, 2, parser3, &#39;91202&#39;, date);
<a name="line182"></a>}
<a name="line183"></a>
<a name="line184"></a>function testYearParsing() {
<a name="line185"></a>  var date = new Date();
<a name="line186"></a>
<a name="line187"></a>  var parser = new goog.i18n.DateTimeParse(&#39;yyMMdd&#39;);
<a name="line188"></a>  assertParsedDateEquals(1999, 12 - 1, 2, parser, &#39;991202&#39;, date);
<a name="line189"></a>
<a name="line190"></a>  var parser2 = new goog.i18n.DateTimeParse(&#39;yyyyMMdd&#39;);
<a name="line191"></a>  assertParsedDateEquals(2005, 12 - 1, 2, parser2, &#39;20051202&#39;, date);
<a name="line192"></a>}
<a name="line193"></a>
<a name="line194"></a>function testGoogDateParsing() {
<a name="line195"></a>  var date = new goog.date.Date();
<a name="line196"></a>
<a name="line197"></a>  var parser = new goog.i18n.DateTimeParse(&#39;yyMMdd&#39;);
<a name="line198"></a>  assertParsedDateEquals(1999, 12 - 1, 2, parser, &#39;991202&#39;, date);
<a name="line199"></a>}
<a name="line200"></a>
<a name="line201"></a>function testHourParsing_hh() {
<a name="line202"></a>  var date = new Date();
<a name="line203"></a>
<a name="line204"></a>  var parser = new goog.i18n.DateTimeParse(&#39;hhmm&#39;);
<a name="line205"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser, &#39;0022&#39;, date);
<a name="line206"></a>  assertParsedTimeEquals(11, 22, undefined, undefined, parser, &#39;1122&#39;, date);
<a name="line207"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser, &#39;1222&#39;, date);
<a name="line208"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser, &#39;2322&#39;, date);
<a name="line209"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser, &#39;2422&#39;, date);
<a name="line210"></a>
<a name="line211"></a>  var parser2 = new goog.i18n.DateTimeParse(&#39;hhmma&#39;);
<a name="line212"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;0022am&#39;, date);
<a name="line213"></a>  assertParsedTimeEquals(11, 22, undefined, undefined, parser2, &#39;1122am&#39;, date);
<a name="line214"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;1222am&#39;, date);
<a name="line215"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;2322am&#39;, date);
<a name="line216"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;2422am&#39;, date);
<a name="line217"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser2, &#39;0022pm&#39;, date);
<a name="line218"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;1122pm&#39;, date);
<a name="line219"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser2, &#39;1222pm&#39;, date);
<a name="line220"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;2322pm&#39;, date);
<a name="line221"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;2422pm&#39;, date);
<a name="line222"></a>}
<a name="line223"></a>
<a name="line224"></a>function testHourParsing_KK() {
<a name="line225"></a>  var date = new Date();
<a name="line226"></a>
<a name="line227"></a>  var parser = new goog.i18n.DateTimeParse(&#39;KKmm&#39;);
<a name="line228"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser, &#39;0022&#39;, date);
<a name="line229"></a>  assertParsedTimeEquals(11, 22, undefined, undefined, parser, &#39;1122&#39;, date);
<a name="line230"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser, &#39;1222&#39;, date);
<a name="line231"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser, &#39;2322&#39;, date);
<a name="line232"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser, &#39;2422&#39;, date);
<a name="line233"></a>
<a name="line234"></a>  var parser2 = new goog.i18n.DateTimeParse(&#39;KKmma&#39;);
<a name="line235"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;0022am&#39;, date);
<a name="line236"></a>  assertParsedTimeEquals(11, 22, undefined, undefined, parser2, &#39;1122am&#39;, date);
<a name="line237"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser2, &#39;1222am&#39;, date);
<a name="line238"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;2322am&#39;, date);
<a name="line239"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;2422am&#39;, date);
<a name="line240"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser2, &#39;0022pm&#39;, date);
<a name="line241"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;1122pm&#39;, date);
<a name="line242"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser2, &#39;1222pm&#39;, date);
<a name="line243"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;2322pm&#39;, date);
<a name="line244"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;2422pm&#39;, date);
<a name="line245"></a>}
<a name="line246"></a>
<a name="line247"></a>function testHourParsing_kk() {
<a name="line248"></a>  var date = new Date();
<a name="line249"></a>
<a name="line250"></a>  var parser = new goog.i18n.DateTimeParse(&#39;kkmm&#39;);
<a name="line251"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser, &#39;0022&#39;, date);
<a name="line252"></a>  assertParsedTimeEquals(11, 22, undefined, undefined, parser, &#39;1122&#39;, date);
<a name="line253"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser, &#39;1222&#39;, date);
<a name="line254"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser, &#39;2322&#39;, date);
<a name="line255"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser, &#39;2422&#39;, date);
<a name="line256"></a>
<a name="line257"></a>  var parser2 = new goog.i18n.DateTimeParse(&#39;kkmma&#39;);
<a name="line258"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;0022am&#39;, date);
<a name="line259"></a>  assertParsedTimeEquals(11, 22, undefined, undefined, parser2, &#39;1122am&#39;, date);
<a name="line260"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser2, &#39;1222am&#39;, date);
<a name="line261"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;2322am&#39;, date);
<a name="line262"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;2422am&#39;, date);
<a name="line263"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser2, &#39;0022pm&#39;, date);
<a name="line264"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;1122pm&#39;, date);
<a name="line265"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser2, &#39;1222pm&#39;, date);
<a name="line266"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;2322pm&#39;, date);
<a name="line267"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;2422pm&#39;, date);
<a name="line268"></a>}
<a name="line269"></a>
<a name="line270"></a>function testHourParsing_HH() {
<a name="line271"></a>  var date = new Date();
<a name="line272"></a>
<a name="line273"></a>  var parser = new goog.i18n.DateTimeParse(&#39;HHmm&#39;);
<a name="line274"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser, &#39;0022&#39;, date);
<a name="line275"></a>  assertParsedTimeEquals(11, 22, undefined, undefined, parser, &#39;1122&#39;, date);
<a name="line276"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser, &#39;1222&#39;, date);
<a name="line277"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser, &#39;2322&#39;, date);
<a name="line278"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser, &#39;2422&#39;, date);
<a name="line279"></a>
<a name="line280"></a>  var parser2 = new goog.i18n.DateTimeParse(&#39;HHmma&#39;);
<a name="line281"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;0022am&#39;, date);
<a name="line282"></a>  assertParsedTimeEquals(11, 22, undefined, undefined, parser2, &#39;1122am&#39;, date);
<a name="line283"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser2, &#39;1222am&#39;, date);
<a name="line284"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;2322am&#39;, date);
<a name="line285"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;2422am&#39;, date);
<a name="line286"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser2, &#39;0022pm&#39;, date);
<a name="line287"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;1122pm&#39;, date);
<a name="line288"></a>  assertParsedTimeEquals(12, 22, undefined, undefined, parser2, &#39;1222pm&#39;, date);
<a name="line289"></a>  assertParsedTimeEquals(23, 22, undefined, undefined, parser2, &#39;2322pm&#39;, date);
<a name="line290"></a>  assertParsedTimeEquals(0, 22, undefined, undefined, parser2, &#39;2422pm&#39;, date);
<a name="line291"></a>}
<a name="line292"></a>
<a name="line293"></a>function testEnglishDate() {
<a name="line294"></a>  var date = new Date();
<a name="line295"></a>
<a name="line296"></a>  var parser = new goog.i18n.DateTimeParse(&#39;yyyy MMM dd hh:mm&#39;);
<a name="line297"></a>
<a name="line298"></a>  // Fails in Safari4/Chrome Winxp because of infrastructure issues, temporarily
<a name="line299"></a>  // disabled. See b/4274778.
<a name="line300"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT);
<a name="line301"></a>  try {
<a name="line302"></a>    assertParsedDateEquals(2006, 7 - 1, 10, parser, &#39;2006 Jul 10 15:44&#39;, date);
<a name="line303"></a>    assertTimeEquals(15, 44, undefined, undefined, date);
<a name="line304"></a>  } catch (e) {
<a name="line305"></a>    expectedFailures.handleException(e);
<a name="line306"></a>  }
<a name="line307"></a>}
<a name="line308"></a>
<a name="line309"></a>function testChineseDate() {
<a name="line310"></a>  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_zh;
<a name="line311"></a>
<a name="line312"></a>  // Javascript month start from 0, July is 7 - 1
<a name="line313"></a>  var date = new Date(2006, 7 - 1, 24, 12, 12, 12, 0);
<a name="line314"></a>  var formatter = new goog.i18n.DateTimeFormat(
<a name="line315"></a>      goog.i18n.DateTimeFormat.Format.FULL_DATE);
<a name="line316"></a>  var dateStr = formatter.format(date);
<a name="line317"></a>  var parser = new goog.i18n.DateTimeParse(
<a name="line318"></a>      goog.i18n.DateTimeFormat.Format.FULL_DATE);
<a name="line319"></a>
<a name="line320"></a>  assertParsedDateEquals(2006, 7 - 1, 24, parser, dateStr, date);
<a name="line321"></a>
<a name="line322"></a>  parser = new goog.i18n.DateTimeParse(
<a name="line323"></a>      goog.i18n.DateTimeFormat.Format.LONG_DATE);
<a name="line324"></a>  assertParsedDateEquals(
<a name="line325"></a>      2006, 7 - 1, 24, parser, &#39;2006\u5E747\u670824\u65E5&#39;, date);
<a name="line326"></a>
<a name="line327"></a>  parser = new goog.i18n.DateTimeParse(
<a name="line328"></a>      goog.i18n.DateTimeFormat.Format.FULL_TIME);
<a name="line329"></a>  assertTrue(parser.parse(&#39;GMT-07:00\u4E0B\u534803:26:28&#39;, date) &gt; 0);
<a name="line330"></a>
<a name="line331"></a>  // Fails in Safari4/Chrome Winxp because of infrastructure issues, temporarily
<a name="line332"></a>  // disabled. See b/4274778.
<a name="line333"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT);
<a name="line334"></a>  try {
<a name="line335"></a>    assertEquals(
<a name="line336"></a>        22, (24 + date.getHours() + date.getTimezoneOffset() / 60) % 24);
<a name="line337"></a>    assertEquals(26, date.getMinutes());
<a name="line338"></a>    assertEquals(28, date.getSeconds());
<a name="line339"></a>  } catch (e) {
<a name="line340"></a>    expectedFailures.handleException(e);
<a name="line341"></a>  }
<a name="line342"></a>
<a name="line343"></a>}
<a name="line344"></a>
<a name="line345"></a>// For languages with goog.i18n.DateTimeSymbols.ZERODIGIT defined, the int
<a name="line346"></a>// digits are localized by the locale in datetimeformat.js. This test case is
<a name="line347"></a>// for parsing dates with such native digits.
<a name="line348"></a>function testDatesWithNativeDigits() {
<a name="line349"></a>  // Language Arabic is one example with
<a name="line350"></a>  // goog.i18n.DateTimeSymbols.ZERODIGIT defined.
<a name="line351"></a>  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_fa;
<a name="line352"></a>
<a name="line353"></a>  // Javascript month starts from 0, July is 7 - 1
<a name="line354"></a>  var date = new Date(2006, 7 - 1, 24, 12, 12, 12, 0);
<a name="line355"></a>  var formatter = new goog.i18n.DateTimeFormat(
<a name="line356"></a>      goog.i18n.DateTimeFormat.Format.FULL_DATE);
<a name="line357"></a>  dateStr = formatter.format(date);
<a name="line358"></a>  var parser = new goog.i18n.DateTimeParse(
<a name="line359"></a>      goog.i18n.DateTimeFormat.Format.FULL_DATE);
<a name="line360"></a>
<a name="line361"></a>  assertParsedDateEquals(2006, 7 - 1, 24, parser, dateStr, date);
<a name="line362"></a>
<a name="line363"></a>  date = new Date(2006, 7 - 1, 24);
<a name="line364"></a>  formatter = new goog.i18n.DateTimeFormat(
<a name="line365"></a>      goog.i18n.DateTimeFormat.Format.SHORT_DATE);
<a name="line366"></a>  dateStr = formatter.format(date);
<a name="line367"></a>  parser = new goog.i18n.DateTimeParse(
<a name="line368"></a>      goog.i18n.DateTimeFormat.Format.SHORT_DATE);
<a name="line369"></a>
<a name="line370"></a>  assertParsedDateEquals(2006, 7 - 1, 24, parser, dateStr, date);
<a name="line371"></a>
<a name="line372"></a>  date = new Date();
<a name="line373"></a>
<a name="line374"></a>  parser = new goog.i18n.DateTimeParse(&#39;y/MM/dd H:mm:ss?SS&#39;);
<a name="line375"></a>  assertParsedDateEquals(2006, 6, 27, parser, &#39;????/??/?? ??:??:?????&#39;, date);
<a name="line376"></a>}
<a name="line377"></a>
<a name="line378"></a>function testTimeZone() {
<a name="line379"></a>  var date = new Date();
<a name="line380"></a>
<a name="line381"></a>  var parser = new goog.i18n.DateTimeParse(&#39;MM/dd/yyyy, hh:mm:ss zzz&#39;);
<a name="line382"></a>  assertTrue(parser.parse(&#39;07/21/2003, 11:22:33 GMT-0700&#39;, date) &gt; 0);
<a name="line383"></a>  var hourGmtMinus07 = date.getHours();
<a name="line384"></a>
<a name="line385"></a>  assertTrue(parser.parse(&#39;07/21/2003, 11:22:33 GMT-0600&#39;, date) &gt; 0);
<a name="line386"></a>  var hourGmtMinus06 = date.getHours();
<a name="line387"></a>  assertEquals(1, (hourGmtMinus07 + 24 - hourGmtMinus06) % 24);
<a name="line388"></a>
<a name="line389"></a>  assertTrue(parser.parse(&#39;07/21/2003, 11:22:33 GMT-0800&#39;, date) &gt; 0);
<a name="line390"></a>  var hourGmtMinus08 = date.getHours();
<a name="line391"></a>  assertEquals(1, (hourGmtMinus08 + 24 - hourGmtMinus07) % 24);
<a name="line392"></a>
<a name="line393"></a>  assertTrue(parser.parse(&#39;07/21/2003, 23:22:33 GMT-0800&#39;, date) &gt; 0);
<a name="line394"></a>  assertEquals((date.getHours() + 24 - hourGmtMinus07) % 24, 13);
<a name="line395"></a>
<a name="line396"></a>  assertTrue(parser.parse(&#39;07/21/2003, 11:22:33 GMT+0800&#39;, date) &gt; 0);
<a name="line397"></a>  var hourGmt08 = date.getHours();
<a name="line398"></a>  assertEquals(16, (hourGmtMinus08 + 24 - hourGmt08) % 24);
<a name="line399"></a>
<a name="line400"></a>  assertTrue(parser.parse(&#39;07/21/2003, 11:22:33 GMT0800&#39;, date) &gt; 0);
<a name="line401"></a>  assertEquals(hourGmt08, date.getHours());
<a name="line402"></a>}
<a name="line403"></a>
<a name="line404"></a>function testWeekDay() {
<a name="line405"></a>  var date = new Date();
<a name="line406"></a>  var parser = new goog.i18n.DateTimeParse(&#39;EEEE, MM/dd/yyyy&#39;);
<a name="line407"></a>
<a name="line408"></a>  assertTrue(parser.parse(&#39;Wednesday, 08/16/2006&#39;, date) &gt; 0);
<a name="line409"></a>  assertDateEquals(2006, 8 - 1, 16, date);
<a name="line410"></a>  assertTrue(parser.parse(&#39;Tuesday, 08/16/2006&#39;, date) == 0);
<a name="line411"></a>  assertTrue(parser.parse(&#39;Thursday, 08/16/2006&#39;, date) == 0);
<a name="line412"></a>  assertTrue(parser.parse(&#39;Wed, 08/16/2006&#39;, date) &gt; 0);
<a name="line413"></a>  assertTrue(parser.parse(&#39;Wasdfed, 08/16/2006&#39;, date) == 0);
<a name="line414"></a>
<a name="line415"></a>  date.setDate(25);
<a name="line416"></a>  parser = new goog.i18n.DateTimeParse(&#39;EEEE, MM/yyyy&#39;);
<a name="line417"></a>  assertTrue(parser.parse(&#39;Wed, 09/2006&#39;, date) &gt; 0);
<a name="line418"></a>  assertEquals(27, date.getDate());
<a name="line419"></a>
<a name="line420"></a>  date.setDate(30);
<a name="line421"></a>  assertTrue(parser.parse(&#39;Wed, 09/2006&#39;, date) &gt; 0);
<a name="line422"></a>  assertEquals(27, date.getDate());
<a name="line423"></a>  date.setDate(30);
<a name="line424"></a>  assertTrue(parser.parse(&#39;Mon, 09/2006&#39;, date) &gt; 0);
<a name="line425"></a>  assertEquals(25, date.getDate());
<a name="line426"></a>}
<a name="line427"></a>
<a name="line428"></a>function testStrictParse() {
<a name="line429"></a>  var date = new Date();
<a name="line430"></a>
<a name="line431"></a>  var parser = new goog.i18n.DateTimeParse(&#39;yyyy/MM/dd&#39;);
<a name="line432"></a>  assertTrue(parser.strictParse(&#39;2000/13/10&#39;, date) == 0);
<a name="line433"></a>  assertTrue(parser.strictParse(&#39;2000/13/40&#39;, date) == 0);
<a name="line434"></a>  assertTrue(parser.strictParse(&#39;2000/11/10&#39;, date) &gt; 0);
<a name="line435"></a>  assertDateEquals(2000, 11 - 1, 10, date);
<a name="line436"></a>
<a name="line437"></a>  parser = new goog.i18n.DateTimeParse(&#39;yy/MM/dd&#39;);
<a name="line438"></a>  assertTrue(parser.strictParse(&#39;00/11/10&#39;, date) &gt; 0);
<a name="line439"></a>  assertTrue(parser.strictParse(&#39;99/11/10&#39;, date) &gt; 0);
<a name="line440"></a>  assertTrue(parser.strictParse(&#39;00/13/10&#39;, date) == 0);
<a name="line441"></a>  assertTrue(parser.strictParse(&#39;00/11/32&#39;, date) == 0);
<a name="line442"></a>  assertTrue(parser.strictParse(&#39;1900/11/2&#39;, date) &gt; 0);
<a name="line443"></a>
<a name="line444"></a>  parser = new goog.i18n.DateTimeParse(&#39;hh:mm&#39;);
<a name="line445"></a>  assertTrue(parser.strictParse(&#39;15:44&#39;, date) &gt; 0);
<a name="line446"></a>  assertTrue(parser.strictParse(&#39;25:44&#39;, date) == 0);
<a name="line447"></a>  assertTrue(parser.strictParse(&#39;15:64&#39;, date) == 0);
<a name="line448"></a>
<a name="line449"></a>  // leap year
<a name="line450"></a>  parser = new goog.i18n.DateTimeParse(&#39;yy/MM/dd&#39;);
<a name="line451"></a>  assertTrue(parser.strictParse(&#39;00/02/29&#39;, date) &gt; 0);
<a name="line452"></a>  assertTrue(parser.strictParse(&#39;01/02/29&#39;, date) == 0);
<a name="line453"></a>}
<a name="line454"></a>
<a name="line455"></a>function testEnglishQuarter() {
<a name="line456"></a>  var date = new Date();
<a name="line457"></a>  var parser = new goog.i18n.DateTimeParse(&#39;QQQQ yyyy&#39;);
<a name="line458"></a>
<a name="line459"></a>  // Fails in Safari4/Chrome Winxp because of infrastructure issues, temporarily
<a name="line460"></a>  // disabled. See b/4274778.
<a name="line461"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT);
<a name="line462"></a>  try {
<a name="line463"></a>    assertParsedDateEquals(2009, 0, 1, parser, &#39;1st quarter 2009&#39;, date);
<a name="line464"></a>  } catch (e) {
<a name="line465"></a>    expectedFailures.handleException(e);
<a name="line466"></a>  }
<a name="line467"></a>}
<a name="line468"></a>
<a name="line469"></a>function testEnglishShortQuarter() {
<a name="line470"></a>  var date = new Date();
<a name="line471"></a>  var parser = new goog.i18n.DateTimeParse(&#39;yyyyQQ&#39;);
<a name="line472"></a>
<a name="line473"></a>  // Fails in Safari4/Chrome Winxp because of infrastructure issues, temporarily
<a name="line474"></a>  // disabled. See b/4274778.
<a name="line475"></a>  expectedFailures.expectFailureFor(goog.userAgent.WEBKIT);
<a name="line476"></a>  try {
<a name="line477"></a>    assertParsedDateEquals(2006, 4 - 1, 1, parser, &#39;2006Q2&#39;, date);
<a name="line478"></a>  } catch (e) {
<a name="line479"></a>    expectedFailures.handleException(e);
<a name="line480"></a>  }
<a name="line481"></a>}
<a name="line482"></a>
<a name="line483"></a>function testFrenchShortQuarter() {
<a name="line484"></a>  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_fr;
<a name="line485"></a>
<a name="line486"></a>  var date = new Date();
<a name="line487"></a>  var parser = new goog.i18n.DateTimeParse(&#39;yyyyQQ&#39;);
<a name="line488"></a>  assertParsedDateEquals(2009, 7 - 1, 1, parser, &#39;2009T3&#39;, date);
<a name="line489"></a>}
<a name="line490"></a>
<a name="line491"></a>function testDateTime() {
<a name="line492"></a>  var dateOrg = new Date(2006, 7 - 1, 24, 17, 21, 42, 0);
<a name="line493"></a>
<a name="line494"></a>  var formatter = new goog.i18n.DateTimeFormat(
<a name="line495"></a>      goog.i18n.DateTimeFormat.Format.MEDIUM_DATETIME);
<a name="line496"></a>  dateStr = formatter.format(dateOrg);
<a name="line497"></a>
<a name="line498"></a>  var parser = new goog.i18n.DateTimeParse(
<a name="line499"></a>      goog.i18n.DateTimeFormat.Format.MEDIUM_DATETIME);
<a name="line500"></a>  var dateParsed = new Date();
<a name="line501"></a>
<a name="line502"></a>  assertParsedDateEquals(dateOrg.getFullYear(), dateOrg.getMonth(),
<a name="line503"></a>      dateOrg.getDate(), parser, dateStr, dateParsed);
<a name="line504"></a>  assertTimeEquals(dateOrg.getHours(), dateOrg.getMinutes(),
<a name="line505"></a>      dateOrg.getSeconds(), undefined, dateParsed);
<a name="line506"></a>}
<a name="line507"></a>
<a name="line508"></a>
<a name="line509"></a>/** @bug 10075434 */
<a name="line510"></a>function testParseDateWithOverflow() {
<a name="line511"></a>
<a name="line512"></a>  // We force the initial day of month to 30 so that it will always cause an
<a name="line513"></a>  // overflow in February, no matter if it is a leap year or not.
<a name="line514"></a>  var dateOrg = new Date(2006, 7 - 1, 30, 17, 21, 42, 0);
<a name="line515"></a>  var dateParsed;  // this will receive the result of the parsing
<a name="line516"></a>
<a name="line517"></a>  var parserMonthYear = new goog.i18n.DateTimeParse(&#39;MMMM yyyy&#39;);
<a name="line518"></a>
<a name="line519"></a>  // The API can be a bit confusing, as this date is both input and output.
<a name="line520"></a>  // Benefit: fields that don&#39;t come from parsing are preserved.
<a name="line521"></a>  // In the typical use case, dateParsed = new Date()
<a name="line522"></a>  // and when you parse &quot;February 3&quot; the year is implied as &quot;this year&quot;
<a name="line523"></a>  // This works as intended.
<a name="line524"></a>  // But because of this we will initialize dateParsed from dateOrg
<a name="line525"></a>  // before every test (because the previous test changes it).
<a name="line526"></a>
<a name="line527"></a>  dateParsed = new Date(dateOrg.getTime());
<a name="line528"></a>  // if preserved February 30 overflows, so we get the closest February day, 28
<a name="line529"></a>  assertParsedDateEquals(
<a name="line530"></a>      2013, 2 - 1, 28, parserMonthYear, &#39;February 2013&#39;, dateParsed);
<a name="line531"></a>
<a name="line532"></a>  // Same as above, but the last February date is 29 (leap year)
<a name="line533"></a>  dateParsed = new Date(dateOrg.getTime());
<a name="line534"></a>  assertParsedDateEquals(
<a name="line535"></a>      2012, 2 - 1, 29, parserMonthYear, &#39;February 2012&#39;, dateParsed);
<a name="line536"></a>
<a name="line537"></a>  // Same as above, but no overflow (Match has 31 days, the parsed 30 is OK)
<a name="line538"></a>  dateParsed = new Date(dateOrg.getTime());
<a name="line539"></a>  assertParsedDateEquals(
<a name="line540"></a>      2013, 3 - 1, 30, parserMonthYear, &#39;March 2013&#39;, dateParsed);
<a name="line541"></a>
<a name="line542"></a>  // The pattern does not expect the day of month, so 12 is interpreted
<a name="line543"></a>  // as year, 12. May be weird, but this is the original behavior.
<a name="line544"></a>  // The overflow for leap year applies, same as above.
<a name="line545"></a>  dateParsed = new Date(dateOrg.getTime());
<a name="line546"></a>  assertParsedDateEquals(
<a name="line547"></a>      12, 2 - 1, 29, parserMonthYear, &#39;February 12, 2013&#39;, dateParsed);
<a name="line548"></a>
<a name="line549"></a>  // We make sure that the fix did not break parsing with day of month present
<a name="line550"></a>  var parserMonthDayYear = new goog.i18n.DateTimeParse(&#39;MMMM d, yyyy&#39;);
<a name="line551"></a>
<a name="line552"></a>  dateParsed = new Date(dateOrg.getTime());
<a name="line553"></a>  assertParsedDateEquals(
<a name="line554"></a>      2012, 2 - 1, 12, parserMonthDayYear, &#39;February 12, 2012&#39;, dateParsed);
<a name="line555"></a>
<a name="line556"></a>  // The current behavior when parsing &#39;February 31, 2012&#39; is to
<a name="line557"></a>  // return &#39;March 2, 2012&#39;
<a name="line558"></a>  // Expected or not, we make sure the fix does not break this.
<a name="line559"></a>  assertParsedDateEquals(
<a name="line560"></a>      2012, 3 - 1, 2, parserMonthDayYear, &#39;February 31, 2012&#39;, dateParsed);
<a name="line561"></a>}
<a name="line562"></a>
<a name="line563"></a>
<a name="line564"></a>/** @bug 9901750 */
<a name="line565"></a>function testStandaloneMonthPattern() {
<a name="line566"></a>  goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_pl;
<a name="line567"></a>  var date1 = new goog.date.Date(2006, 7 - 1);
<a name="line568"></a>  var date2 = new goog.date.Date();
<a name="line569"></a>  var formatter =
<a name="line570"></a>      new goog.i18n.DateTimeFormat(&#39;LLLL yyyy&#39;);
<a name="line571"></a>  var parser =
<a name="line572"></a>      new goog.i18n.DateTimeParse(&#39;LLLL yyyy&#39;);
<a name="line573"></a>  var dateStr = formatter.format(date1);
<a name="line574"></a>  assertParsedDateEquals(
<a name="line575"></a>      date1.getFullYear(), date1.getMonth(), undefined, parser, dateStr, date2);
<a name="line576"></a>
<a name="line577"></a>  // Sanity tests to make sure MMM... (and LLL...) formats still work for
<a name="line578"></a>  // different locales.
<a name="line579"></a>  var symbols = [
<a name="line580"></a>    goog.i18n.DateTimeSymbols_en,
<a name="line581"></a>    goog.i18n.DateTimeSymbols_pl
<a name="line582"></a>  ];
<a name="line583"></a>
<a name="line584"></a>  for (var i = 0; i &lt; symbols.length; i++) {
<a name="line585"></a>    goog.i18n.DateTimeSymbols = symbols[i];
<a name="line586"></a>    var tests = {
<a name="line587"></a>      &#39;MMMM yyyy&#39;: goog.i18n.DateTimeSymbols.MONTHS,
<a name="line588"></a>      &#39;LLLL yyyy&#39;: goog.i18n.DateTimeSymbols.STANDALONEMONTHS,
<a name="line589"></a>      &#39;MMM yyyy&#39;: goog.i18n.DateTimeSymbols.SHORTMONTHS,
<a name="line590"></a>      &#39;LLL yyyy&#39;: goog.i18n.DateTimeSymbols.STANDALONESHORTMONTHS
<a name="line591"></a>    };
<a name="line592"></a>
<a name="line593"></a>    for (var format in tests) {
<a name="line594"></a>      var parser = new goog.i18n.DateTimeParse(format);
<a name="line595"></a>      var months = tests[format];
<a name="line596"></a>      for (var m = 0; m &lt; months.length; m++) {
<a name="line597"></a>        var dateStr = months[m] + &#39; 2006&#39;;
<a name="line598"></a>        var date = new goog.date.Date();
<a name="line599"></a>        assertParsedDateEquals(2006, m, undefined, parser, dateStr, date);
<a name="line600"></a>      }
<a name="line601"></a>    }
<a name="line602"></a>  }
<a name="line603"></a>}
</pre>


</body>
</html>
